package com.ssm.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.ssm.dao.EnterpriseEntityMapper;
import com.ssm.entity.EnterpriseEntity;
import com.ssm.entity.StudentEntity;
import com.ssm.service.EnterpriseService;
import myUtils.myPage;

@Service("EnterpriseServiceImpl")
@Transactional
public class EnterpriseServiceImpl implements EnterpriseService {
	
    @Autowired
    private EnterpriseEntityMapper mapper;
    
	@Override
	public void save(EnterpriseEntity enterprise) {
		mapper.insert(enterprise);
		return;
	}

	@Override
	public boolean update(EnterpriseEntity enterprise) {
		try {
			int result = mapper.updateByPrimaryKeySelective(enterprise);
			System.out.print(result);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public boolean delete(String id) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public EnterpriseEntity findById(String id) {
		EnterpriseEntity company = mapper.selectByPrimaryKey(id);
		return company;
	}

	@Override
	public List<EnterpriseEntity> findWithPage(Integer page, Integer pageNum, String name, Integer field) {
		if (page == null || pageNum == null) {
			return new ArrayList<EnterpriseEntity>();
		} else {
			PageHelper.startPage(page, pageNum);
			try {
				List<EnterpriseEntity> companys= mapper.findAll(name, field);
				return companys;
			}finally {
				// 保证线程安全
				PageHelper.clearPage();
			}
		}
	}

	@Override
	public List<EnterpriseEntity> searchByName(String name) {
		PageHelper.startPage(myPage.PAGE, myPage.PAGENUM);
		try {
			List<EnterpriseEntity> companys= mapper.searchByName(name);
			return companys;
		}finally {
			// 保证线程安全
			PageHelper.clearPage();
		}
	}

	@Override
	public List<EnterpriseEntity> searchByField(Integer field) {
		PageHelper.startPage(myPage.PAGE, myPage.PAGENUM);
		try {
			List<EnterpriseEntity> companys= mapper.searchByField(field);
			return companys;
		}finally {
			// 保证线程安全
			PageHelper.clearPage();
		}
	}

	@Override
	public EnterpriseEntity findByAccountId(String accountId) {
		EnterpriseEntity company = mapper.selectByAccountId(accountId);
		return company;
	}
}
